package com.softa.web.controller.custom;

import com.softa.bean.LoginReq;
import com.softa.enummodel.LoginEnum;
import com.softa.shiro.authc.CaptchaAuthenticationToken;
import com.softa.utils.Constants;
import com.softa.utils.IpUtil;
import com.softa.web.controller.base.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 *  登陆
 */
@Controller
@RequestMapping("/custom/login")
public class CustomLoginController extends BaseController {

    @RequestMapping(method = RequestMethod.GET)
    public String showLoginForm(HttpServletRequest req, Model model) {
        String exceptionClassName = (String)req.getAttribute("shiroLoginFailure");
        String error = null;
        if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
            error = "用户名/密码错误";
        } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
            error = "用户名/密码错误";
        } else if(exceptionClassName != null) {
            error = "其他错误：" + exceptionClassName;
        }
        logger.error(error);
        model.addAttribute("error", error);
        return Constants.MENU_FRONT+"/login";
    }

}
